package com.woniuxy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.woniuxy.dto.EmployeeDto;
import com.woniuxy.entity.Employee;
import com.woniuxy.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/employee")
//@Api(tags = "员工管理")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 删除员工
     *
     * @PathVariable 方法形参的值从地址栏上获取，如果名字不同，则需要使用PathVariable(“变量名”)来指定获取的值
     */
    // @ApiOperation("删除员工")
    //   @ApiImplicitParam(name = "id",value = "员工ID",required = true,dataType = "Integer")
    @DeleteMapping("/deleteById/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer id) {
        System.out.println("删除员工：" + id);
        //2.调用业务层写到数据库中
        boolean save =   employeeService.removeById(id);
        if (save) {
            return ResponseEntity.ok(true);
        }else {
            return ResponseEntity.badRequest().body(false);
        }
    }



    /**
     * 删除一批员工
     *
     * @PathVariable 方法形参的值从地址栏上获取，如果名字不同，则需要使用PathVariable(“变量名”)来指定获取的值
     */
    //  @ApiOperation("删除一批员工")
    // @ApiImplicitParam(name = "ids",value = "员工ID",required = true,dataType = "String[]")
    @PostMapping("/deleteBatch")
    public ResponseEntity<Boolean> deleteBatch(@RequestBody String[] ids) {
        System.out.println("删除员工：" + ids);
        //2.调用业务层写到数据库中
        boolean save = employeeService.removeBatchByIds(Arrays.stream(ids).collect(Collectors.toList()));
        if (save) {
            return ResponseEntity.ok(true);
        }else {
            return ResponseEntity.badRequest().body(false);
        }
    }

    /**
     * 修改员工
     */
    //  @ApiOperation("修改员工")
    //  @ApiImplicitParam(name = "employee", value = "员工信息", required = true, dataType = "com.woniuxy.entity.employee")
    @PutMapping
    public ResponseEntity<Boolean> update(@RequestBody Employee employee) {
        boolean save =  employeeService.updateById(employee);
        return ResponseEntity.ok(save);
    }

      public void hello23(){

      }

}
